if (document.getElementById("goback")) {
	var goBack = document.getElementById("goback");

	goBack.onclick = function() {
		history.go(-1);
	}
}
function getinputvalue(id)
{
	var obj = document.getElementById(id);
	return obj.value;
}
function setinputvalue(id,value)
{
	var obj = document.getElementById(id);
	obj.value = value;
}
function clearinput(classname) {
	var obj = document.getElementsByClassName(classname);
	if (obj) {
		var len = obj.length;
		for (i = 0; i < len; i++) {
			obj[i].value = '';
		}
	}

}

function tohref(url) {
	document.location.href = url;
}

function getjsonstr(css) {
	var objArr = document.getElementsByClassName(css);
	var len = objArr.length;
	var json = {};
	var key = arguments[1] || "";
	for (i = 0; i < len; i++) {
		var n = '';
		if (key == "") {
			n = objArr[i].id;
		} else {
			n = objArr[i].dataset.key;
		}

		var val = objArr[i].value;
		json[n] = val;
	}

	var json_str = JSON.stringify(json);
	return json_str;
}


function getarrstr(css) {
	var objArr = document.getElementsByClassName(css);
	var len = objArr.length;
	var Arr = [];
	var key = '';
	if (arguments[1]) {
		key = arguments[1];
	}
	for (i = 0; i < len; i++) {
		var n = '';
		if (key == "") {
			n = objArr[i].id;
		} else {
			n = objArr[i].dataset.key;
		}

		var val = objArr[i].value;
		Arr.push(n + '::' + val);
	}
	var arr_str = Arr.join("||");
	return arr_str;
}

function inputmoney(obj) {
	obj.value = obj.value.replace(/[^\d.]/g, ""); //清除“数字”和“.”以外的字符  
	obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的  
	obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
	obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); //只能输入两个小数  
	if (obj.value.indexOf(".") < 0 && obj.value != "") { //以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额 
		obj.value = parseFloat(obj.value);
	}
}

function mustnum(obj) {
	val = obj.value.replace(/[^0-9-]+/, '');
	obj.value = val;
}

function getradiovalue(name) {
	var okaidan = document.getElementsByName(name);
	var len = okaidan.length;
	var value = "";
	for (i = 0; i < len; i++) {
		if (okaidan[i].checked == true)
			value = okaidan[i].value;
	}
	return value;
}

function deldiv(obj) {
	var ceng = 1;
	if (arguments[1]) {
		ceng = arguments[1];
	}
	switch (ceng) {
		case 1:
			obj.parentNode.removeChild(obj);
			break;
		case 2:
			obj.parentNode.parentNode.removeChild(obj.parentNode);
			break;
		case 3:
			obj.parentNode.parentNode.parentNode.removeChild(obj.parentNode.parentNode);
			break;
	}

}
//根据日期xxxx-xx-xx xx:xx:xx 生成时间戳
function shijianchuo(date) {

	date = date.substring(0, 19);
	date = date.replace(/-/g, '/');
	var timestamp = new Date(date).getTime();
	timestamp = timestamp / 1000;
	return timestamp;
}

function isJSON(str) {
	if (typeof str == 'string') {
		try {
			var obj = JSON.parse(str);
			if (typeof obj == 'object' && obj) {
				return obj;
			} else {
				return false;
			}

		} catch (e) {
			return false;
		}
	} else {
		return false;
	}
}

function ajax(url, method, data, callback) {
	var tp = typeof url;
	tp = tp.toUpperCase();
	var dataType = arguments[4] || '' ;
	
	if (tp == 'STRING') {
		method = method.toUpperCase();
		var dd = {}; //必带的数据
		if (data) {
			for (i in data) {
				dd[i] = data[i];
			}
		}
		var params = '';
		if (dd) {
			params = formatParams(dd); //options.data请求的数据
		}
		console.log("url--"+url);
		console.log('params--'+params);
		var xhr;
		//考虑兼容性
		if (window.XMLHttpRequest) {
			xhr = new XMLHttpRequest();
		} else if (window.ActiveObject) { //兼容IE6以下版本
			xhr = new ActiveXobject('Microsoft.XMLHTTP');
		}
		//启动并发送一个请求

		if (method == "GET") {
			var pot = url.indexOf('?');
			if (pot > 0) {
				url = url + '&' + params;
			} else {
				url = url + "?" + params;
			}
			console.log(url);
			xhr.open("GET", url, true);
			xhr.send(null);
		} else if (method == "POST") {
			xhr.open("post", url, true);

			//设置表单提交时的内容类型
			//Content-type数据请求的格式
			xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
			xhr.send(params);
		}
		var timeout = 10000;

		//    设置有效时间
		setTimeout(function() {
			if (xhr.readySate != 4) {
				xhr.abort();
			}
		}, timeout)

		//    接收
		//     options.success成功之后的回调函数  options.error失败后的回调函数
		//xhr.responseText,xhr.responseXML  获得字符串形式的响应数据或者XML形式的响应数据
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				var status = xhr.status;
				if(dataType == "TEXT")
				{
					callback(xhr.responseText);
				}else
				{
					var Arr = isJSON(xhr.responseText);
					if (Arr) {
						callback(Arr);
					} else {
						callback(xhr.responseText);
					}
				}
			}
		}
	} else {
		ajax2(url);
	}

}

function ajax2(options) {
	options = options || {}; //调用函数时如果options没有指定，就给它赋值{},一个空的Object
	options.type = (options.type || "POST").toUpperCase(); /// 请求格式GET、POST，默认为GET
	options.dataType = options.dataType || "json"; //响应数据格式，默认json
	options.timeout = options.timeout || 10000; //超时时间
	options.contentType = options.contentType || "application/json";

	var params = "";
	if (options.data) {
		params = formatParams(options.data); //options.data请求的数据
	}


	var xhr;

	//考虑兼容性
	if (window.XMLHttpRequest) {
		xhr = new XMLHttpRequest();
	} else if (window.ActiveObject) { //兼容IE6以下版本
		xhr = new ActiveXobject('Microsoft.XMLHTTP');
	}

	//启动并发送一个请求
	if (options.type == "GET") {
		xhr.open("GET", options.url + "?" + params, true);
		xhr.send(null);
	} else if (options.type == "POST") {
		xhr.open("post", options.url, true);

		//设置表单提交时的内容类型
		//Content-type数据请求的格式
		xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		xhr.send(params);
	}

	//    设置有效时间
	setTimeout(function() {
		if (xhr.readySate != 4) {
			xhr.abort();
		}
	}, options.timeout)

	//    接收
	//     options.success成功之后的回调函数  options.error失败后的回调函数
	//xhr.responseText,xhr.responseXML  获得字符串形式的响应数据或者XML形式的响应数据
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			var status = xhr.status;
			if (status >= 200 && status < 300 || status == 304) {
				options.success && options.success(xhr.responseText, xhr.responseXML);
			} else {
				options.error && options.error(status);
			}
		}
	}
}

//格式化请求参数
function formatParams(data) {
	var arr = [];
	for (var name in data) {
		arr.push(encodeURIComponent(name) + "=" + encodeURIComponent(data[name]));
	}
	arr.push(("v=" + Math.random()).replace(".", ""));
	return arr.join("&");

}
//基本的使用实例
/*ajax({
        url:"http://server-name/login",
        type:'post',
        data:{
            username:'username',
            password:'password'
        },
        dataType:'json',
        timeout:10000,
        contentType:"application/json",
        success:function(data){
　　　　　　。。。。。。//服务器返回响应，根据响应结果，分析是否登录成功
        },
        //异常处理
        error:function(e){
            console.log(e);
        }
    })*/
//字符串转换为时间戳
function stringtotime(date) {
	//date = '2015-03-05 17:59:00'; 
	var date = date.replace(/-/g, '/'); //必须把日期'-'转为'/'
	var timestamp = new Date(date).getTime();
	return timestamp / 1000;
}
//时间戳转换为字符串
function timetostring(timestamp) {
	//var timestamp = '1425553097';
	var date = new Date(timestamp * 1000); //时间戳为10位需*1000，时间戳为13位的话不需乘1000
	var Y = date.getFullYear();
	var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
	var D = date.getDate();
	var h = date.getHours();
	var m = date.getMinutes();
	var s = date.getSeconds();
	var time = Y + "-" + M + "-" + D + " " + h + ":" + m + ":" + s;

	console.log('time', time);

	var act = '';
	if (arguments[1]) {
		act = arguments[1];
	}

	switch (act) {
		case 'day':
			time = Y + "-" + M + "-" + D;
			break;
		case 'hour':
			time = Y + "-" + M + "-" + D + " " + h;
			break;
		case 'min':
			time = Y + "-" + M + "-" + D + " " + h + ":" + m;
			break;

	}

	return time;
}

function timetoday(timestamp) {
	//var timestamp = '1425553097';
	var d = new Date(timestamp * 1000); //根据时间戳生成的时间对象
	var date = (d.getFullYear()) + "-" +
		(d.getMonth() + 1) + "-" +
		(d.getDate());
	return date;
}

function addoption(id, data) {
	var type = typeof(id);
	if (type == 'string') {
		id = document.querySelector(id);
	}
	var objOption = document.createElement("option");
	var len = data.length;
	for (i = 0; i < len; i++) {
		objOption.value = data['value'];
		objOption.text = data['text'];
		id.add(objOption);
	}
}
//添加时间和现在差多少时间
function chatime(timer) {
	var timestamp = Date.parse(new Date()) / 1000;
	var cha_time = timestamp - timer;
	var txt = '';
	if (cha_time <= 0) {
		txt = '刚刚';
	}
	if (cha_time < 3600) {
		var cha = Math.ceil(cha_time / 60)
		txt = cha + '分钟前';
	}
	if (cha_time >= 3600 && cha_time < 86400) {
		var cha = Math.ceil(cha_time / 3600)
		txt = cha + '小时前';
	}
	if (cha_time >= 86400) {
		var cha = Math.ceil(cha_time / 86400);
		if (cha >= 365) {
			txt = '1年前';
		} else {
			txt = cha + '天前'
		}
	}
	return txt;

}

//两个数相加
function bcadd(num1,num2)
{
    var scale = !arguments[2] ? 2 : arguments[2];
    scale = scale + 1;
    var mul = Math.pow(10,scale);
    num1 = parseFloat(num1) * mul;
    num2 = parseFloat(num2) * mul;
    var num = (num1 + num2) / mul;
    var pos = num.toString().indexOf('.');
    if(pos != -1)
    {
        var numArr = num.toString().split('.');
        scale = scale - 1;
        num = numArr[0]+'.'+ numArr[1].substring(0,scale);
    }
    return num;
}
//两个数相减
function bcsub(num1,num2)
{
    var scale = !arguments[2] ? 2 : arguments[2];
    scale = scale + 1;
    var mul = Math.pow(10,scale);
    num1 = parseFloat(num1) * mul;
    num2 = parseFloat(num2) * mul;
    var num = (num1 - num2) / mul;
    var pos = num.toString().indexOf('.');
    if(pos != -1)
    {
        var numArr = num.toString().split('.');
        scale = scale - 1;
        num = numArr[0]+'.'+ numArr[1].substring(0,scale);
    }
    return num;
}
//两个数相乘
function bcmul(num1,num2)
{
    var scale = !arguments[2] ? 2 : arguments[2];
    scale = scale + 1;
    var mul = Math.pow(10,scale);
    num1 = parseFloat(num1) * mul;
    num2 = parseFloat(num2) * mul;
    var mul2 = Math.pow(10,scale * 2);
    var num = (num1 * num2) / mul2;
    var pos = num.toString().indexOf('.');
    if(pos != -1)
    {
        var numArr = num.toString().split('.');
        scale = scale - 1;
        num = numArr[0]+'.'+ numArr[1].substring(0,scale);
    }
    return num;
}
//两个数相除
function bcdiv(num1,num2)
{
    var scale = !arguments[2] ? 2 : arguments[2];
    var scale2 = scale + 1;
    var mul = Math.pow(10,scale2);
    num1 = parseFloat(num1) * mul;
    num2 = parseFloat(num2) * mul;
    var mul2 = Math.pow(10,scale2 * 2);
    var num = (num1 / num2) ;
    var pos = num.toString().indexOf('.');
    if(pos != -1)
    {
        var numArr = num.toString().split('.');
        scale = scale - 1;
        num = numArr[0]+'.'+ numArr[1].substring(0,scale);
    }
    return num ;
}
//两个数比较
function bccomp(num1,num2)
{
	var scale = !arguments[2] ? 2 : arguments[2];
    var scale2 = scale + 1;
    var mul = Math.pow(10,scale2);
    num1 = parseFloat(num1) * mul;
    num2 = parseFloat(num2) * mul;
	if(num1 == num2)
	{
		return 0;
	}
	if(num1 > num2)
	{
		return 1;
	}
	if(num1 < num2)
	{
		return -1;
	}
}


function empty(val)
{
    if(val == null)
    {
        return true;
    }
    var type = typeof(val);
    if(type == 'boolean')
    {
        return val;
    }
    if(type == "number")
    {
        if(val == 0)
        {
            return true;
        } 
    }
    if(type == "string")
    {
        if(val == ' ' || val == '0' || val== '')
        {
            return true;
        } 
    }
    if(type == 'object')
    {
        if(val.length == undefined)
        {
            var len = 0;
            for(i in val)
            { 
                len = len+1;
                break;
            }
            if(len == 0)
            {
                return true;
            }
        }else
        {
            var len = val.length;
            if(len == 0)
            {
                return true;
            }
        } 
    }
    return false;
}

function getQueryVariable(variable) {
	var query = window.location.search.substring(1);
	var vars = query.split("&");
	for (var i = 0; i < vars.length; i++) {
		var pair = vars[i].split("=");
		if (pair[0] == variable) {
			return pair[1];
		}
	}
	return (false);
}

Array.prototype.indexOf = function(val) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == val) return i;
	}
	return -1;
};
Array.prototype.remove = function(val) {
	var index = this.indexOf(val);
	if (index > -1) {
		this.splice(index, 1);
	}
};
